//
//  LifeWebViewCtrl.m
//  laowu
//
//  Created by Northwan on 15/4/30.
//  Copyright (c) 2015年 长沙市岳麓区立早网络科技有限公司. All rights reserved.
//

#import "LifeWebViewCtrl.h"

@interface LifeWebViewCtrl ()<UIWebViewDelegate>
@property (weak, nonatomic) IBOutlet UIWebView *webView;
@property(nonatomic,copy)NSString *url;
@property(nonatomic,copy)NSString *titleName;
@end

@implementation LifeWebViewCtrl

+(instancetype)initWithUrl:(NSString *)url  title:(NSString *)title{
    LifeWebViewCtrl *object = [[LifeWebViewCtrl alloc]init];
    object.url = url;
    object.titleName = title;
    return object;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.title;
    _webView.delegate = self;
    [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_url]]];
}

-(void)webViewDidFinishLoad:(UIWebView *)webView{
    NSString *theTitle=[webView stringByEvaluatingJavaScriptFromString:@"document.title"];
    self.title = theTitle;
    
    CGSize actualSize = [webView sizeThatFits:CGSizeZero];
    _webView.scrollView.contentSize = actualSize;
    
    //根据webview加载的情况判断是否添加上返回的手势事件
    if (![self isCanBack]) {
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
            self.navigationController.interactivePopGestureRecognizer.enabled = NO;
        }
    }else{
        if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]){
            self.navigationController.interactivePopGestureRecognizer.enabled = YES;
        }
    }
}

-(BOOL)isCanBack{
    return ![_webView canGoBack];
}

@end
